<?php

class BaseManager {

	protected $db;

	protected $obj;

	protected $result;

	protected $filter;

	public function __construct() {
		$this->db = MySqlHelper::getInstance();
	}

	public function setObj($obj) {
		$this->obj = $obj;
	}

	public function getResult() {
		return $this->result;
	}

	public function setFilter($filter) {
		$this->filter = $filter;
	}

	protected function getCondition() {
		$conditions = '';

		if (!empty($this->filter)) {
			foreach ($this->filter AS $k => $v) {
				if (is_array($v)) {
					$condition[] = $k . ' ' . $v[0] . ' \'' . $v[1] . '\'';
				} else {
					$condition[] = $k . ' = \'' . $v . '\'';
				}
			}

			$conditions = ' WHERE ' . implode(' AND ', $condition);
		}

		return $conditions;
	}
}